package com.teen9g.infoplatformserver.controller;

import com.github.pagehelper.PageInfo;
import com.teen9g.dto.NoticePageQueryDTO;
import com.teen9g.entity.Notice;
import com.teen9g.infoplatformserver.service.NoticeService;
import com.teen9g.result.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 公告控制器
 *
 * @author teen9g
 */
@Slf4j
@CrossOrigin
@RestController
@RequestMapping("/notice")
public class NoticeController {

    @Autowired
    private NoticeService noticeService;


    @GetMapping("/page")
    public Result<PageInfo<Notice>> page(NoticePageQueryDTO noticePageQueryDTO) {
        log.info("公告分页查询:{}", noticePageQueryDTO);
        PageInfo<Notice> pageInfo = noticeService.pageQuery(noticePageQueryDTO);
        return Result.success(pageInfo);
    }

    @GetMapping("/{id}")
    public Result<Notice> getById(@PathVariable Integer id) {
        log.info("根据id查询公告:{}", id);
        Notice notice = noticeService.getById(id);
        return Result.success(notice);
    }
}
